// dom-traverse.js
(function() {
    
    var parseDOM = {
        tree: [],
        traverse: function(elem) {
            if (!elem || elem === null) {
                throw new Error("Could not start traversing DOM from specified element: " + elem);
            }
            if ((typeof elem.tagName) !== 'undefined') {
                parseDOM.tree.push(elem);
            }
            var i = 0;
            var kid = elem.childNodes[i];
            while (kid) {
                parseDOM.traverse(kid);
                i++
                kid = elem.childNodes[i];
            }
        }
    };
    
    window.onload = function() {
        parseDOM.tree = [];
        parseDOM.traverse(document);
        console.log(parseDOM.tree);
    };
    
})();